package homework;

public class Work2 {
    public static void main(String[] args) {
        Student s1=Student.getInstance();
        Student s2=Student.getInstance();
        Student s3=Student.getInstance();
        Student s4=Student.getInstance();
        Student s5=Student.getInstance();
        Student s6=Student.getInstance();
        Student s7=Student.getInstance();
        Student s8=Student.getInstance();
        Student s9=Student.getInstance();
        Student s10=Student.getInstance();
        Student s11=Student.getInstance();
        System.out.println(s10);
        System.out.println(s11);

    }
}

class Student {
    int ID;
    static int count = 0;
    {
        if(count<10){
            ID=count++;
        }
    }

    private Student() {
    }

    //该方法线程不安全---
    public static Student getInstance() {
        if (count < 10) {
            return new Student();
        }
        return null;
    }
}
